package com.smf.lsc.msrf.seata.config;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;

/**
 * c微服务引擎fegin配置信息，包括扫描类、拦截器等
 * c拦截fegin调用,补充header信息,便于登录信息在服务间传递
 * Created on 2021/11/19.
 *
 * @author ln
 * @since 1.0
 */
@Configuration
@ConditionalOnProperty(prefix="lsc.service",name = "type", havingValue = "fegin",matchIfMissing=true)
@Order(1)
@Slf4j
public class SeataRequestInterceptor implements RequestInterceptor {
	
	@Override
    public void apply(RequestTemplate requestTemplate) {
        // 解决seata的xid未传递
        String xid = RootContext.getXID();
        requestTemplate.header(RootContext.KEY_XID, xid);
    }
}